let HelloWorld = {
  onCommand: function(event) {
    dump("Hello world!\n");
    //    debugger;
    dump("Debugger finished");
  }
};

function pdump (msg) {
  dump("\n\n        *****  " + msg + "  **** \n\n\n");
}


var KarlCentral = {
 prefs: null,
 monitorURL: "",
 refreshInterval: 1000*2,

 startup: function() {

    // Register to receive notifications of preference changes
    this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
      .getService(Components.interfaces.nsIPrefService)
       .getBranch("karlcentral.");
    this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    this.prefs.addObserver("", this, false);

    this.monitorURL = this.prefs.getCharPref("to_monitor_url");

    //this.refreshInformation();		
    //window.setInterval(this.refreshInformation, this.refreshInterval);
 },
	
 shutdown: function() {
    this.prefs.removeObserver("", this);
  },
	
 // Called when events occur on the preferences
	
 observe: function(subject, topic, data) {
    if (topic != "nsPref:changed") {
      return;
    };

    switch(data) {
        case "to_monitor_url":
	    this.monitorURL = this.prefs.getCharPref("to_monitor_url").toUpperCase();
	    this.refreshInformation();
	    break;
    };
 },
	
 // Switches to watch a different stock, by symbol
	
 watchStock: function(newURL) {
    this.prefs.setCharPref("to_monitor_url", newURL);
 },
	
 // Refresh the stock information
	
 refreshInformation: function() {

    function infoReceived () {
      var output = httpRequest.responseText;
      pdump("In refreshInformation: ");
    };

    function transferFailed (evt) {
      pdump("Error received: " + httpRequest.status);
    }

    var httpRequest = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
        .createInstance(Components.interfaces.nsIXMLHttpRequest);

    httpRequest.open("GET", KarlCentral.monitorURL, true);
    httpRequest.addEventListener("error", transferFailed, false);
    httpRequest.onload = infoReceived;
    httpRequest.send(null);
 }
}

// Install load and unload handlers

window.addEventListener("load", function(e) { KarlCentral.startup(); }, false);
window.addEventListener("unload", function(e) { KarlCentral.shutdown(); }, false);
